Perf: Throttle parallel typechecks in Find All References - #20128
Perf: Throttle parallel typechecks in Find All References#20128xperiandri wants to merge 2 commits into
Conversation
T-Gro
left a comment
There was a problem hiding this comment.
🤖 AI review (@expert-reviewer): no significant issues found. Please verify independently.
Reviewed the throttling implementation for correctness:
use semaphorecombined withreturn! Task.WhenAll(tasks)correctly awaits within theusescope, avoiding the commonSemaphoreSlimuse-after-dispose pitfall (this would be a bug withreturninstead ofreturn!).semaphore.WaitAsync(ct)is placed before thetry, soRelease()runs only when a permit was actually acquired — no risk of over-release, and cancelled waiters correctly skip the release.- The expensive
start ct taskruns only after acquiring a permit, so concurrency is genuinely capped. max 1 Environment.ProcessorCountguarantees a valid (>= 1) semaphore count.
Cancellation and exception-aggregation semantics match the existing whenAll. LGTM.
149109e to
c5582ba
Compare
❗ Release notes requiredYou can open this PR in browser to add release notes: open in github.dev Caution No release notes found for the changed paths (see table below). Please make sure to add an entry with an informative description of the change as well as link to this pull request, issue and language suggestion if applicable. Release notes for this repository are based on Keep A Changelog format. The following format is recommended for this repository: `* . (PR #XXXXX)`
If you believe that release notes are not necessary for this PR, please add NO_RELEASE_NOTES label to the pull request.
|
c5582ba to
a86b21f
Compare
Fixes #20127
Problem
Project.FindFSharpReferencesAsynclaunched oneCancellableTaskper document in the project simultaneously viaCancellableTask.whenAll, causing an unbounded number of parallel typechecks (one per document) at once during Find All References / Rename.Fix
CancellableTask.whenAllThrottled maxDegreeOfParallelisminCancellableTasks.fs, using aSemaphoreSlimto cap concurrency while preserving cancellation semantics.Project.FindFSharpReferencesAsync(WorkspaceExtensions.fs), capping concurrency tomax 1 Environment.ProcessorCount.